<div class="breadcrumb">
    <a href="#">全部分类</a>
    <span>></span>
    <a href="#">新鲜水果</a>
    <span>></span>
    <a href="#">商品详情</a>
</div>

<script>
    function UpdateGoodsPrice() {
        //获取单价数量计算总价格
        let $price = $(".show_pirze em").html();
        let $num = $(".num_show").val();
        let $sum = $(".total em");  //总价

        $sum.html(Number($price) * Number($num) + "元");
    }

    $(function () {

        let $num = $(".num_show");
        UpdateGoodsPrice();
        let $plus = $(".add");
        let $lose = $(".minus");

        $plus.click(function () {

            let Num = Number($num.val()) + 1;
            $num.val(Num);
            UpdateGoodsPrice();
        })

        $lose.click(function () {
            let Num = Number($num.val()) - 1;
            if (Num <= 0) {
                return
            }
            $num.val(Num);
            UpdateGoodsPrice();
        })

        //失去焦点跟新
        $num.blur(function () {
            UpdateGoodsPrice();
        })

        $num.change(function () {
            $num.val($num.val().replace(/[^\d]/g, ""));
        })

        //发送添加购物车请
        let $cart = $("#add_cart")

        $cart.click(function () {
            let skuId = $cart.attr("skuid");
            let count = $num.val();
            let jsonData = {"skuId": skuId, "count": count};
            $.post("/cart/addCart", jsonData, function (data) {
                if (data.code == 200) {
                    let $count = $("#show_count");
                    $count.html(data.CartCount);
                } else {
                    alert(data.msg);
                }
            })
        })

    })
</script>

<div class="goods_detail_con clearfix">
    <div class="goods_detail_pic fl"><img src="{{.goods.Image}}"></div>

    <div class="goods_detail_list fr">
        <h3>{{.goods.Name}}</h3>
        <p>{{.goods.Desc}}</p>
        <div class="prize_bar">
            <span class="show_pirze">¥<em>{{.goods.Price}}</em></span>
            <span class="show_unit">单  位：{{.goods.Unite}}</span>
        </div>
        <div class="goods_num clearfix">
            <div class="num_name fl">数 量：</div>
            <div class="num_add fl">
                <input type="text" class="num_show fl" value="1">
                <a href="javascript:;" class="add fr">+</a>
                <a href="javascript:;" class="minus fr">-</a>
            </div>
        </div>
        <div class="total">总价：<em>16.80元</em></div>
        <div class="operate_btn">
            <a href="javascript:;" class="buy_btn">立即购买</a>
            <a href="javascript:;" class="add_cart" id="add_cart" skuid="{{.goods.Id}}">加入购物车</a>
        </div>
    </div>
</div>

<div class="main_wrap clearfix">
    <div class="l_wrap fl clearfix">
        <div class="new_goods">
            <h3>新品推荐</h3>
            <ul>
                {{range .goodsNew}}
                    <li>
                        <a href="/goodsDetail?id={{.Id}}"><img src="{{.Image}}"></a>
                        <h4><a href="/goodsDetail?id={{.Id}}">{{.Name}}</a></h4>
                        <div class="prize">￥{{.Price}}</div>
                    </li>
                {{end}}
            </ul>
        </div>
    </div>

    <div class="r_wrap fr clearfix">
        <ul class="detail_tab clearfix">
            <li class="active">商品介绍</li>
            <li>评论</li>
        </ul>

        <div class="tab_content">
            <dl>
                <dt>商品详情：</dt>
                <dd>
                    {{.goods.Desc}}
                </dd>
            </dl>
        </div>

    </div>
</div>
